var carousel = document.querySelector("ul"),
	left_arrow = document.querySelector(".left_arrow"),
	right_arrow = document.querySelector(".right_arrow"),
	controls = document.querySelectorAll("ol li"),
	ol = document.querySelector("ol"),
	carousel_box = document.querySelector(".carousel_box"),
	now_index = 0;
Srll();

right_arrow.addEventListener("click", function() {
	SRLL(a = 1);
}) //右移点击
left_arrow.addEventListener("click", function() {
	SRLL(a = 2);
}) //左移点击
ol.addEventListener("click", function(e) {
	var i = 0;
	if(e.target.nodeName == "LI") {
		for(var i = 0; i < controls.length; i++) {
			if(e.target == controls[i]) {
				now_index = i;
				SRLL();
			}
		}
	}
}) //小圆点点击
function Srll() {
	var kk=setInterval(function() {
		SRLL(a=1);
	for(var i = 0; i < controls.length; i++) {
		if(i == now_index) {
			controls[i].style.backgroundColor = "red";
		} else {
			controls[i].style.backgroundColor = "black";
		}
	}
	}, 2000)//自动播放和点击停止播放。
	carousel_box.addEventListener("click", function() {
						window.clearInterval(kk);
						say();
	})
	var time=2000;
	function say(){
					setTimeout(Srll,time);
	}      //点击后的等待时间
} 

function SRLL(a) {
	switch(a) {
		case 1:
			++now_index >= 5 ? (now_index = 0) : "";
			break;
		case 2:
			--now_index <= -1 ? (now_index = 4) : "";
			break;
	}
	carousel.style.transform = "translateX(-" + now_index * 100 + "%)";
	for(var i = 0; i < controls.length; i++) {
		if(i == now_index) {
			controls[i].style.backgroundColor = "red";
		} else {
			controls[i].style.backgroundColor = "black";
		}
	}
}   //公用函数，圆点高亮，图片移动。